"use strict";
const e = require("../../common/vendor.js"),
	a = require("../../api/debounceapi.js"),
	r = require("../../api/request.js");
Math || (t + u)();
const t = () => "./components/search-author.js",
	u = () => "../Common-components/card-flow.js",
	s = {
		__name: "search",
		setup(t) {
			e.useCssVars((e => ({
				"3c2c74d4": i.topSearchHeight
			})));
			const u = e.ref([]),
				s = e.ref([]),
				o = e.ref([]),
				c = e.ref(!0),
				l = e.ref(!1),
				v = e.ref(!1),
				n = e.ref(""),
				i = e.reactive({
					categorySearch: !1,
					topSearchHeight: "120rpx",
					author: !1
				}),
				h = a.debounceapi((async () => {
					console.log("输入时触发"), c.value = "" == n.value, l.value = "" != n.value, v.value = !1, i
						.author = !1;
					const e = await r.requestApi("/search_travel", {
						keywords: n.value
					});
					o.value = e.data
				})),
				f = e.ref([]),
				d = e.ref([]),
				y = e.ref([]);
			async function p(a) {
				if (n.value = a, q.value = 1, 0 === m.value) {
					const e = await r.requestApi("/search_result", {
						keywords: a
					});
					d.value = e.data.userTravels, v.value = !0
				} else {
					const e = await r.requestApi("/search_author", {
						keywords: a,
						page: 1
					});
					i.author = !0, y.value = e.data
				}
				i.categorySearch = !0, i.topSearchHeight = "210rpx", c.value = !1, l.value = !1, f.value = e.wx$1
					.getStorageSync("searchKeywords") || [], f.value.unshift(a);
				const t = Array.from(new Set(f.value));
				e.wx$1.setStorageSync("searchKeywords", t), u.value.unshift(a), u.value = Array.from(new Set(u
					.value))
			}

			function _() {
				u.value = [], e.wx$1.removeStorageSync("searchKeywords")
			}
			async function g() {
				if (console.log("获取焦点时触发" + n.value), c.value = "" == n.value, l.value = "" != n.value, v.value = !
					1, i.categorySearch = !1, i.topSearchHeight = "120rpx", i.author = !1, "" != n.value) {
					const e = await r.requestApi("/search_travel", {
						keywords: n.value
					});
					o.value = e.data
				}
			}
			async function w() {
				await p(n.value)
			}
			e.onMounted((async () => {
				const a = e.wx$1.getStorageSync("searchKeywords");
				u.value = a || [];
				const t = await r.requestApi("/hot_city");
				s.value = t.data
			}));
			const S = e.ref(["游记", "作者"]),
				m = e.ref(0);
			const q = e.ref(1);
			return e.onReachBottom((async () => {
				if (!i.categorySearch) return !1;
				if (q.value++, 0 === m.value) {
					const e = await r.requestApi("/paging_search_result", {
						page: q.value,
						keywords: n.value
					});
					d.value = [...d.value, ...e.data]
				} else if (1 === m.value) {
					const e = await r.requestApi("/search_author", {
						page: q.value,
						keywords: n.value
					});
					y.value = [...y.value, ...e.data]
				}
			})), e.onLoad((() => {
				e.index.$on("loginSuccess", (async e => {
					await p(n.value)
				}))
			})), (a, r) => e.e({
				a: e.o([e => n.value = e.detail.value, (...a) => e.unref(h) && e.unref(h)(...a)]),
				b: e.o(g),
				c: e.o(w),
				d: n.value,
				e: i.categorySearch
			}, i.categorySearch ? {
				f: e.f(S.value, ((a, r, t) => ({
					a: e.t(a),
					b: m.value === r ? 1 : "",
					c: m.value === r ? 1 : "",
					d: r,
					e: e.o((e => async function(e) {
						m.value = e, q.value = 1, await p(n.value), 0 === e ? (v
							.value = !0, i.author = !1) : (v.value = !1, i
							.author = !0)
					}(r)), r)
				})))
			} : {}, {
				g: e.s(a.__cssVars()),
				h: e.s(a.__cssVars()),
				i: u.value.length > 0
			}, u.value.length > 0 ? {
				j: e.o(_),
				k: e.f(u.value, ((a, r, t) => ({
					a: e.t(a),
					b: r,
					c: e.o((e => p(a)), r)
				})))
			} : {}, {
				l: e.f(s.value, ((a, r, t) => ({
					a: a.image,
					b: e.t(a._id),
					c: e.t(a.count),
					d: r,
					e: e.o((e => p(a._id)), r)
				}))),
				m: c.value,
				n: e.s(a.__cssVars()),
				o: e.f(o.value, ((a, r, t) => ({
					a: e.t(a),
					b: r,
					c: e.o((e => p(a)), r)
				}))),
				p: l.value,
				q: e.s(a.__cssVars()),
				r: i.author
			}, i.author ? {
				s: e.p({
					authorData: y.value
				}),
				t: e.s(a.__cssVars())
			} : {}, {
				v: e.p({
					userTravels: d.value
				}),
				w: v.value,
				x: e.s(a.__cssVars()),
				y: e.s(a.__cssVars())
			})
		}
	},
	o = e._export_sfc(s, [
		["__scopeId", "data-v-738b40f5"]
	]);
wx.createPage(o);